package com.jeesite.modules.task.taskgroup.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.annotation.RepeatSubmit;
import com.jeesite.modules.exam.quota.entity.DcSupExamQuotaOrg;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.task.taskgroup.entity.DcSupTaskGroupUnit;
import com.jeesite.modules.task.taskgroup.service.DcSupTaskGroupUnitService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.task.taskgroup.entity.DcSupTaskGroup;
import com.jeesite.modules.task.taskgroup.service.DcSupTaskGroupService;

import java.util.List;

/**
 * dc_sup_task_groupController
 * @author xhc
 * @version 2022-06-28
 */
@Controller
@RequestMapping(value = "${adminPath}/task/dcSupTaskGroup")
public class DcSupTaskGroupController extends BaseController {

	@Autowired
	private DcSupTaskGroupService dcSupTaskGroupService;
	@Autowired
	private DcSupTaskGroupUnitService dcSupTaskGroupUnitService;
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupTaskGroup get(String id, boolean isNewRecord) {
		return dcSupTaskGroupService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequestMapping(value = {"list", ""})
	public String list(DcSupTaskGroup dcSupTaskGroup, Model model) {
		model.addAttribute("dcSupTaskGroup", dcSupTaskGroup);
		dcSupTaskGroup.setCreateBy(UserUtils.getUser().getUserCode());
		List<DcSupTaskGroup> list = dcSupTaskGroupService.findList(dcSupTaskGroup);
		model.addAttribute("assessmentUnit", list);
		return "modules/task/taskgroup/dcSupTaskGroupIndex";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupTaskGroup> listData(DcSupTaskGroup dcSupTaskGroup, HttpServletRequest request, HttpServletResponse response) {
		dcSupTaskGroup.setPage(new Page<>(request, response));
		Page<DcSupTaskGroup> page = dcSupTaskGroupService.findPage(dcSupTaskGroup);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequestMapping(value = "form")
	public String form(DcSupTaskGroup dcSupTaskGroup, Model model) {
		model.addAttribute("dcSupTaskGroup", dcSupTaskGroup);
		return "modules/task/taskgroup/dcSupTaskGroupForm";
	}


	/**
	 * 保存数据
	 */

	@PostMapping(value = "save")
	@RepeatSubmit
	@ResponseBody
	public String save(@Validated DcSupTaskGroup dcSupTaskGroup) {
		dcSupTaskGroup.setCreateBy(UserUtils.getUser().getUserCode());
		dcSupTaskGroupService.save(dcSupTaskGroup);
		return renderResult(Global.TRUE, text("保存成功！"));
	}
	
	/**
	 * 停用数据
	 */

	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DcSupTaskGroup dcSupTaskGroup) {
		dcSupTaskGroup.setStatus(DcSupTaskGroup.STATUS_DISABLE);
		dcSupTaskGroupService.updateStatus(dcSupTaskGroup);
		return renderResult(Global.TRUE, text("停用成功"));
	}
	
	/**
	 * 启用数据
	 */

	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DcSupTaskGroup dcSupTaskGroup) {
		dcSupTaskGroup.setStatus(DcSupTaskGroup.STATUS_NORMAL);
		dcSupTaskGroupService.updateStatus(dcSupTaskGroup);
		return renderResult(Global.TRUE, text("启用成功"));
	}
	
	/**
	 * 删除数据
	 */
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupTaskGroup dcSupTaskGroup) {
		dcSupTaskGroupService.delete(dcSupTaskGroup);
		return renderResult(Global.TRUE, text("删除成功！"));
	}
	/**
	 * 获取自己的常用组集合
	 */
	@RequestMapping(value = "groupList")
	@ResponseBody
	public Object groupList(DcSupTaskGroup dcSupTaskGroup) {
		dcSupTaskGroup.setCreateBy(UserUtils.getUser().getUserCode());
		return dcSupTaskGroupService.findList(dcSupTaskGroup);
	}


}